# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=sbase
pkgver=0_git20210730
_gitrev=7d60e2cabbe07495ee74f3d5e705f1e3470148eb
pkgrel=2
pkgdesc="Suckless collection of portable unix tools"
url="https://core.suckless.org/sbase/"
arch="all"
license="MIT"
install="$pkgname.post-install $pkgname.post-upgrade $pkgname.pre-deinstall"
subpackages="$pkgname-doc"
source="https://dev.alpinelinux.org/archive/$pkgname/$pkgname-$pkgver.tar.gz
	setup-sbase.in
	"
options="!check"  # no tests provided

snapshot() {
	local tarball="$pkgname-$pkgver.tar.gz"

	clean
	deps

	mkdir -p "$srcdir"
	cd "$srcdir"

	msg 'Clonning source repository'
	git clone git://git.suckless.org/sbase ${tarball%.tar.gz}
	git -C ${tarball%.tar.gz} checkout $_gitrev

	# Create reproducible tarball (always same checksum for same content).
	tar -cz \
		--owner=0 --group=0 --mtime='1970-01-02' \
		--exclude-vcs \
		-f "$SRCDEST/$tarball" ${tarball%.tar.gz}

	msg "Uploading $tarball"
	rsync --progress "$SRCDEST/$tarball" dev.alpinelinux.org:/archive/$pkgname/
}

prepare() {
	default_prepare
	sed "s/@@VERSION@@/$pkgver/" "$srcdir"/setup-sbase.in > setup-sbase
}

build() {
	make sbase-box CFLAGS="$CFLAGS"
}

package() {
	make sbase-box-install DESTDIR="$pkgdir" PREFIX=/ MANPREFIX=/usr/share/man VERSION=$pkgver
	find "$pkgdir"/bin -type l -delete

	install -D -m755 setup-sbase -t "$pkgdir"/usr/sbin/
}

sha512sums="
3087354abe4ce86c0e6776ac27f6d5afc43aa641b5068a97b412239494994d9b6fcd9605cbcdc21f592a6b3c44391f707368f78cd7f5f172b2cf4af0c0751752  sbase-0_git20210730.tar.gz
87ac5fc9db7865fa7cbcdd66e3a6a84d35859ea71253e7dccd46f96db58a7680fa6787957ec5a8f80953d75c10640fa112c907c4cf34b2e3097193d2f10b0d6c  setup-sbase.in
"
